<?php
include '../conn.php';
include 'a-cookie.php';
if($_SESSION["a-rank"]==1)
{
    die("权限不够，不能进入");
}
?>
<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>新闻/开放年度毕业管理-管理员端</title>
    <link rel="stylesheet" type="text/css" href="../css/htmleaf-demo.css">
    <link rel="stylesheet" type="text/css" href="../css/nav.css">
    <link rel="stylesheet" type="text/css" href="../fonts/iconfont.css">

    <link rel="stylesheet" href="../css/bootstrap-theme.css"/>

    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <link rel="stylesheet" href="../css/bootstrap-theme.min.css"/>
    <link rel="stylesheet" href="../css/bootstrap.css"/>
    <script type="text/javascript" src="../js/bootstrap3.0.3.min.js"></script>

    <script type="text/javascript" src="../js/nicEdit.js"></script>
    <script type="text/javascript">

    </script>


    <style>
        #out {
            position: absolute;
            right: 30px;
            top: 20px;
            z-index: 100000;
        }

        .topx {
            margin: 0px;
            padding-top: 50px;
            position: fixed;
            z-index: 999;
            /*浮动部分*/
            /*float:left; */
        }

        .navfont {
            font-family: "黑体";
            font-size: 1.5em;
            padding-top: 10px;
        }

        .indexborder {
            border: 1px transparent;
            border-color: transparent;
            border-color: rgba(0, 0, 0, 0);
            margin-left: 285px;
            margin-right: 5%;

        }

        .bodycolor {
            background-color: gainsboro;
        }

        .box-inline {
            box-shadow: 0px 2px 2px grey;
        }

        .indexdiv1 {
            margin-top: 70px;
            margin-bottom: 20px;
            /*margin-left: 0px;*/
            padding: 2% 2% 2% 2%;
            width: 100%;
            /*height:400px;*/
        }

        .navbackground-a {
            background-color: #463c19;
        }

        .indexfooter {
            background-color: dimgray;
            /*height: 50px;*/
            position: absolute;
            bottom: 0px;
            width: 100%;
        }

        .footer-p {
            padding-top: 10px;
            padding-left: 210px;
        }

        .paneldiv {
            margin-left: 40px;
        }

        .black_overlay {
            /*  弹窗样式*/
            display: none;
            position: absolute;
            top: 0%;
            left: 0%;
            width: 100%;
            height: 100%;
            background-color: black;
            z-index: 1001;
            -moz-opacity: 0.6;
            opacity: .60;
            filter: alpha(opacity=80);
        }

        .white_content {
            display: none;
            position: absolute;
            top: 10%;
            left: 10%;
            width: 80%;
            height: 80%;
            border: 16px solid lightblue;
            background-color: white;
            z-index: 1002;
            overflow: auto;
        }

        .white_content_small {
            display: none;
            position: absolute;
            top: 20%;
            left: 20%;
            width: 60%;
            height: 60%;
            border: 16px solid #807345;
            background-color: white;
            z-index: 1002;
            overflow: auto;
        }

        @media screen and (max-width: 900px) {
            #nav {
                width: 25%;
            }

            #news {
                width: 100%;
                font-size: 70%;
            }

            .paneldiv {
                width: 100%;
                font-size: 90%;
            }

            .indexborder {
                margin-left: 35%;
                margin-right: 5%;
            }

            .footer-p {
                padding-left: 26%;
            }
        }

        @media screen and (max-width: 400px) {
            #nav {
                width: 25%;
            }

            .navfont {
                font-size: 1em;
            }

            #news {
                width: 100%;
                font-size: 60%;
            }

            .paneldiv {
                width: 100%;
                font-size: 65%;
            }

            .indexborder {
                margin-left: 35%;
                margin-right: 5%;
            }

            .footer-p {
                padding-left: 26%;
            }
        }
    </style>


</head>

<body class="bodycolor">

<nav class="navbar navbar-default navbar-fixed-top" style="clear: left;">
    <div class="container">
        <div class="navbar-right navfont" id="navbar-collapse">
            <p>华软网络技术系毕业管理系统</p>
        </div>
    </div>
    <a href="a-cookie.php?cookie=out" id="out">退出</a>
</nav>


<div class="nav topx navbackground-a" id="nav">
    <div>

        <div style="border-bottom:1px solid rgba(255,255,255,.1)"><img src="../images/mini.png"></div>
    </div>
    <ul>
        <li class="nav-item">
            <a href="a-index.php"><i class="my-icon nav-icon icon_2"></i><span>首页</span><i class="my-icon nav-more"></i></a>

        </li>
        <li class="nav-item">
            <a href="a-newsManage.php"><i class="my-icon nav-icon icon_5"></i><span>开放/新闻管理</span><i
                    class="my-icon nav-more"></i></a>
        </li>


        <li class="nav-item">
            <a href="a-all.php"><i class="my-icon nav-icon icon_6"></i><span>答辩汇总</span><i class="my-icon nav-more"></i></a>

        </li>
        <li class="nav-item">
            <a href="#"><i class="my-icon nav-icon icon_3"></i><span>答辩分组</span><i class="my-icon nav-more"></i></a>
            <ul>
                <li>
                    <a href="a-denfenAsign.php"><span>小组分配</span></a>
                </li>
                <li>
                    <a href="a-denfenInterAsign.php"><span>组内分配</span></a>
                </li>
            </ul>
        </li>
        <li class="nav-item">
            <a href="#"><i class="my-icon nav-icon icon_5"></i><span>资料管理</span><i class="my-icon nav-more"></i></a>
            <ul>
                <li>
                    <a href="a-sInfromationmange.php"><span>学生资料管理</span></a>
                </li>
                <li>
                    <a href="a-tInfromationmange.php"><span>教师资料管理</span></a>
                </li>
            </ul>
        </li>
    </ul>
</div>


<div class="indexborder">
    <center style="margin-left: 0px;">
        <div class="box-inline indexdiv1 panel panel-default auto" align="center">
            <div class="panel panel-primary panel-success">
                <div class="panel-heading" style="padding: 0px;color: black;font-style:initial;">
                    <h3 class="panel-title " style="background-color: #807345;padding: 15px;color: whitesmoke;">
                        新闻管理</h3>
                </div>
                <div class="panel-body">
                    <div class="table-responsive">
                        <table class="table  table-hover  table-striped  table-condensed">


                            <div id="fade" class="black_overlay">  <!--//弹窗开始代码-->
                            </div>
                            <div id="MyDiv" class="white_content_small">
                                <div style="text-align: right; cursor: default; height: 5px;padding:10px;font-size: 15px">
                                    <span style="font-size: 20px;" onclick="CloseDiv('MyDiv','fade')">关闭</span>
                                </div>

                                <form action="news.php" method="post">
                                    <input type="text" id="num" name="newId" style="display:none;"><br>
                                    标题<input maxlength="20" name="title" id="title" style="width:50%"><br><br>
                                    <!--              /需要导入nicedit.js文件，和nicEdit.gif;-->
                                    内容<textarea name="content" id="content" cols="100"
                                                style="width:50%;   height:150px"></textarea><br><br>
                                    类别<select name="type" id="type" name="type" style="width:50%;height: 30px">
                                        <option value="校园">校园</option>
                                        <option value="科研">科研</option>
                                        <option value="艺术">艺术</option>
                                    </select><br><br>
                                    作者<input type="text" id="author" name="author" style="width:50%"><br><br>

                                    <input type="submit" value="保存" name="actionType" id="actionType">
                                </form>
                            </div>
                            <!--//弹窗结束代码

                            -->


                            <thead>
                            <tr class="thcolor">
                                <th></th>
                                <th style="display: none">序号</th>
                                <th>标题</th>
                                <th>内容</th>
                                <th>类别</th>
                                <th>作者</th>
                                <th>时间</th>
                                <th>操作</th>


                            </tr>
                            </thead>
                            <tbody>
                            <?php
                            $sql = "select NewsId,NewName,Content,category,author,Time from  defensesummary";
                            $result = $conn->query($sql);
                            while ($row = $result->fetch_assoc()) {
                                ?>
                                <tr>
                                    <td><input type="checkbox" name="ckbox"></td>
                                    <td style="display: none"><?= $row["NewsId"] ?></td>
                                    <td><?= $row["NewName"] ?></td>
                                    <td><?php echo $row["Content"] ?></td>
                                    <td><?php echo $row["category"] ?></td>
                                    <td><?php echo $row["author"] ?></td>
                                    <td><?php echo $row["Time"] ?></td>
                                    <td><input type="button" value="修改" class=" btn-xs "
                                               style="background-color: #463c19;color: white;"
                                               onclick="ShowDiv('MyDiv','fade',this)"></td>
                                </tr>
                            <?php
                            }
                            ?>
                            </tbody>
                        </table>
                        <div style="margin-top: 20px;">
                            <div style="float: right;margin-right: 15px;"><input type="button" value="删除"
                                                                                 class="btn btn-primary btn-success"
                                                                                 style="background-color:#463c19 "
                                                                                 onclick="dataDrop()"></div>
                            <div style="float: right;margin-right: 20px;"><input type="button" value="添加"
                                                                                 class="btn btn-primary btn-success"
                                                                                 style="background-color:#463c19 "
                                                                                 onclick="ShowDiv('MyDiv','fade',this)">
                            </div>

                        </div>
                    </div>
                </div>
            </div>

            <div class="panel panel-primary panel-success">
                <div class="panel-heading" style="padding: 0px;color: black;font-style:initial;">
                    <h3 class="panel-title" style="background-color: #807345;padding: 15px;color: whitesmoke;">
                        选择开放年份</h3>
                </div>
                <div class="panel-body">
                    <div>
                        <div class="" style="width: 70%;">
                            <!--                <table class="table  table-hover  table-striped  table-condensed" style="word-break: break-all">-->
                            <!--                    <thead>-->
                            <!--                    <tr>-->
                            <!--                        <th>已开放年份</th>-->
                            <!--                        <th>未开放年份</th>-->
                            <!--                    </tr>-->
                            <!--                    </thead>-->
                            <!--                    <tbody>-->
                            <!--                    <tr>-->
                            <!--                        <td id="up">2018,2016,2015</td>-->
                            <!--                        <td id="off">2019</td>-->
                            <!--                    </tr>-->
                            <!---->
                            <!--                    </tbody>-->
                            <!--                </table>-->

                            请输入开放或关闭年份：<input type="text" style="width: 60px" id="year"><br><br>
                            <input type="submit" value="开放" class="btn btn-primary btn-success"
                                   style="background-color:#463c19 " onclick="yearOpen()">
                            <input type="submit" value="关闭" class="btn btn-primary btn-success"
                                   style="background-color:#463c19 " onclick="yearDown()"><br><br>
                        </div>
                    </div>

                </div>
            </div>


            <div style="height: 100px;"></div>


        </div>
    </center>

</div>


<!--		<footer class="indexfooter container-fluid  bottom">-->
<!--			<p class="footer-p" align="center">地址：广东省广州市从化区经济开发区高技术产业园广从南路548号 | 电话：020－87818918 邮编：510990 | 网站公安备案编号：4401840100050 粤ICP备：05085382号 站长统计</p>-->
<!--		</footer>-->


<script>
    window.jQuery || document.write('<script src="../js/jquery-1.11.0.min.js"><\/script>')
</script>
<script type="text/javascript" src="../js/nav.js"></script>
<script type="text/javascript">  //弹窗实现
    function showOut(a, b, c, d, e) {

        var num = document.getElementById("num");
        var title = document.getElementById("title");

        var content = document.getElementById("content");
        var types = document.getElementById("type").getElementsByTagName("OPTION");
        var author = document.getElementById("author");


        num.value = a;
        num.readOnly = true;
        title.value = b;
        content.value = c;

        if (d == "校园") {
            types[0].selected = "selected";
        }
        else if (d == "科研") {
            types[1].selected = "selected";
        }
        else {
            types[2].selected = "selected";
        }
        author.value = e;


    }


    //弹出隐藏层
    function ShowDiv(show_div, bg_div, t) {
        bkLib.onDomLoaded(function () {
            nicEditors.allTextAreas()
        });
        var bt = document.getElementById("actionType");
        if (t.value == "修改") {
            var parent = t.parentNode.parentNode;
            var tdArr = parent.getElementsByTagName("TD");
            var num = tdArr[1].innerText;
            var title = tdArr[2].innerText;
            var content = tdArr[3].innerText;
            var type = tdArr[4].innerText;
            var author = tdArr[5].innerText;
            bt.value = "保存";
            showOut(num, title, content, type, author);
        }
        else {
            bt.value = "添加";
            showOut(null, null, null, "校园", null);
            document.getElementById("num").readOnly = false;
        }


        document.getElementById(show_div).style.display = 'block';
        document.getElementById(bg_div).style.display = 'block';
        var bgdiv = document.getElementById(bg_div);
        bgdiv.style.width = document.body.Width;
        // bgdiv.style.height = $(document).height();
        $("#" + bg_div).height($(document).height());


    }
    ;
    //关闭弹出层
    function CloseDiv(show_div, bg_div) {
        document.getElementById(show_div).style.display = 'none';
        document.getElementById(bg_div).style.display = 'none';
    }
    ;
    //function open(){
    //	myWindow=window.open('a-index.html', '_self');
    //}
</script>
<script type="text/javascript">//数据的删除
    function dataDrop() {
        alert("ddd")
        var ckbox = document.getElementsByName("ckbox");
        var dropNode;
        var num;
        var deleteArr = new Array();
        var numArr = new Array();
        var j = 0;
        for (var i = 0; i < ckbox.length; i++) {
            if (ckbox[i].checked) {
                dropNode = ckbox[i].parentNode.parentNode.getElementsByTagName("TD")[1];
                num = dropNode.innerText;
                deleteArr[j] = dropNode;  //保存要删除的行
                numArr[j] = num;     //保存要删除的序号
                j++;
            }
        }
        var r = confirm("是否删除所选数据！"); //弹窗确认
        if (r == true) {
            for (var n = 0; n < deleteArr.length; n++) {
                $.ajax({                //post提交要删除数据行
                    type: "POST",
                    url: "news.php",
                    data: "actionType=delete&indexId=" + numArr[n],
                    success: function (msg) {

                        if (msg == "failed") {
                            alert("第" + numArr[n] + "条数据删除失败");
                            header("Location:a-newsManage.php");
                        }
                    }
                });
                deleteArr[n].parentNode.parentNode.removeChild(deleteArr[n].parentNode);//删除数据行
            }
        }

    }


    function yearOpen() {
        var year = document.getElementById("year").value;
        $.ajax({
            type: "POST",
            url: "news.php",
            data: "actionType=open&year=" + year,
            success: function (msg) {
                alert(msg);
            }
        });

    }
    function yearDown() {
        var year = document.getElementById("year").value;
        $.ajax({
            type: "POST",
            url: "news.php",
            data: "actionType=down&year=" + year,
            success: function (msg) {
                alert(msg);
            }
        });
    }
</script>

</body>

</html>